package edu.ped.android.adapter;

import edu.ped.android.nfc.R;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class GridViewHomeAdapter extends BaseAdapter {

	private String[] mTextActivity; 
	private Drawable[] mIconActivity;
	private Context mContext;
	private LayoutInflater inflater;
	private View[] views;
	
	
	class ViewHolder{
		ImageView iv;
		TextView tv;
	}

	public GridViewHomeAdapter(Context c,String[] textActivity, Drawable[] icons) {
		mContext = c;
		mIconActivity = icons;
		mTextActivity = textActivity;
		inflater = LayoutInflater.from(mContext);
		views = new View[textActivity.length];
	}

	public int getCount() {
		return mTextActivity.length;
	}

	public Object getItem(int arg0) {
		return views[arg0];
	}

	public long getItemId(int arg0) {
		return arg0;
	}
	
	

	public View getView(int position, View convertView, ViewGroup parent) {

		final ViewHolder holder;

		if (convertView == null) {
			holder = new ViewHolder();

			convertView = inflater.inflate(R.layout.gridview_home_layout, null);
			holder.tv = (TextView) convertView.findViewById(R.gridview_home_layout.text_activity);
			holder.iv = (ImageView) convertView.findViewById(R.gridview_home_layout.icon_activity);
			LayoutParams params = new LinearLayout.LayoutParams(110, 110);
			
			holder.iv.setLayoutParams(params);
			holder.tv.setText(mTextActivity[position]);
			holder.iv.setImageDrawable(mIconActivity[position]);
			convertView.setTag(mTextActivity[position]);
			convertView.setId(position);
		} 
		return convertView;

	}

}
